package week09;
import java.util.*;

public class week0901 {

	    public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        Map<String,List<Integer>> map = new TreeMap<String, List<Integer>>();
	        ArrayList<String> linelist = new ArrayList<String>();
	        int line = 1;
	        while(sc.hasNextLine()) {
	            String s = sc.nextLine();
	            if(s.equals("!!!!!")) {
	                break;
	            }
	            linelist.add(s);

	            String[] ss = s.trim().split("\\s+");
	            for (String t:
	                 ss) {
	                if(map.containsKey(t)) {
	                    if(!map.get(t).contains(line))
	                    map.get(t).add(line);
	                }
	                else {
	                    ArrayList<Integer> temp = new ArrayList<Integer>();
	                    temp.add(line);
	                    map.put(t,temp);
	                }
	            }
	            line++;
	        }
	        for (Map.Entry<String, List<Integer>> entry:
	                map.entrySet()) {
	            System.out.println(entry.getKey() + "=" + entry.getValue().toString());
	        }
	        while (sc.hasNextLine()) {
	            String s = sc.nextLine();
	            String[] ss = s.trim().split("\\s+");
	            List<Integer> list = new ArrayList<Integer>();

	            for (int i = 0; i < linelist.size(); i++) {
	                boolean contain = true;
	                for (String str:
	                     ss) {
	                    if(!linelist.get(i).contains(str)) {
	                        contain = false;
	                        break;
	                    }
	                }
	                if(contain) {
	                    list.add(i+1);
	                }
	            }
	            if(list.isEmpty()) {
	                System.out.println("found 0 results");
	                continue;
	            }
	            System.out.println(list.toString());
	            for (int i:
	                 list) {
	                System.out.println("line "+i+":"+linelist.get(i-1));
	            }

	        }
	        sc.close();
	    }

	}

